SAVEDIR = "/home/philonov/projects/archi-site/maket-images"

def mainz():
  try:
    print "\nSaving files to " + SAVEDIR + ", which was set by SAVEDIR variable...\n"
  except:
    print '\nYou must set SAVEDIR varialbe which value must be a location to save files, '+\
      'e.g.\n\n\tSAVEDIR = "/home/user/images/"\n\nType it.'
    return

  try:
    image = gimp.image_list()[0]
    print "Image was haved.\n"
  except:
    print "No open files. Open one.\n"
    return

  i = len(image.layers)-1

  interlace = 0
  compression = 9
  bkgd = 0
  gama = 1
  offs = 0
  phys = 0
  time = 0
  for layer in image.layers:
    layerName = "0"*(6-len(str(i))) + str(i);
    print "=== Layer number " + layerName + " ===\n"
    filename = SAVEDIR + "/" + layerName + ".png"
    raw_filename = filename
    try:
      pdb.file_png_save(image, layer, filename, raw_filename, interlace,compression,bkgd,gama,offs,phys,time)
    except:
      print "No saving.\n"
    i = i - 1

  print "done.\n\n"

mainz()

